<!--
 * @Author: 李兵 964368540@qq.com
 * @Date: 2024-05-25 10:13:50
 * @LastEditors: libing 964368540@qq.com
 * @LastEditTime: 2024-06-05 19:11:49
 * @FilePath: \crm\pages\form\photo-order-form.vue
 * @Description: 新增日程  from
-->
<template>
  <view class="form-wrap">
    <uni-forms
      ref="baseForm"
      :modelValue="formData"
      :rules="rules"
      label-position="left"
      label-width="80px"
    >
      <view class="forms-item-wrap">
        <uni-forms-item label="日程内容" name="name" :required="true">
          <uni-easyinput
            type="text"
            trim="all"
            v-model="formData.name"
            placeholder="请输入日程内容"
            :inputBorder="false" 
            placeholderStyle="color:#C1C5C9;fontSize:15px"
          />
        </uni-forms-item>
        <uni-forms-item label="日程类型" name="type" :required="true">
          <SelectPicker :range="DAY_TASK_ARRAY" v-model="formData.type">
              <view :class="[ formData.type?'uni-input-input':'select-wrap']">{{ formData.type? DAY_TASK_MAP[formData.type]: '请选择日程类型'  }}</view>
          </SelectPicker>
        </uni-forms-item>
        <uni-forms-item label="时间区间" name="time" :required="true">
            <uni-datetime-picker type="date" :clear-icon="false" v-model="formData.time" placeholder="请选择时间区间" :border="false" />
        </uni-forms-item>
        <uni-forms-item label="通知时间" name="notice" :required="true">
          <SelectPicker :range="NOTICE_TYPE_ARRAY" v-model="formData.notice">
              <view :class="[ formData.notice?'uni-input-input':'select-wrap']">{{ formData.notice? NOTICE_TYPE_MAP[formData.notice]: '请选择日程类型'  }}</view>
          </SelectPicker>
        </uni-forms-item>
       </view>
    </uni-forms>
    <bottombox>
        <u-button type="error" text="保存" @click="onSumbit" :loading="loading" :disabled="loading"></u-button>
    </bottombox>
  </view>
</template>
<script>
import { addCalendar } from "@/apis/customer/index";
import { NOTICE_TYPE_ARRAY, NOTICE_TYPE_MAP, DAY_TASK_ARRAY, DAY_TASK_MAP} from '@/contacts/calendar'
import SelectPicker from '@/components/select-picker/select-picker'
export default {
  name: "schedule-form",
  components: {
    SelectPicker
  },
  onLoad() {},
  data() {
    return {
      NOTICE_TYPE_ARRAY,
      NOTICE_TYPE_MAP, 
      DAY_TASK_ARRAY, 
      DAY_TASK_MAP,
      loading: false,
      rules: {},
      formData: {
        name: null, // 日程内容
        type: null, // 日程类型
        time: [], // 时间区间
        notice: null, // 通知时间
      },
    };
  },
  methods: {
    async onSumbit() {
      const valid = await this.$refs.baseForm.validate();
      if (valid) {
        // try {
          this.loading = true;
          await addCalendar(this.formData);
          this.loading = false;
          uni.navigateBack({
            delta: 1, // 返回的页面数
          });
        // } catch (error) {
        //     this.loading = false
        // }
      }
    },
  },
};
</script>
<style lang="scss" scoped>
  page {
    background: #f2f4f5;
  }
</style>
